<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	
	private $devel_mode = true; // true to bypass to ext/importer
	private $debug_sql 	= false; //debug sql in firebug
	private $debug_mail = false; // send email on log
	private $version = 0.3;
	
	protected function _initError(){
		ini_set('display_errors',Utils::isProduction()?0:E_ALL);
		set_error_handler("Utils::handleError");
	}
	
	protected function _initDataBase(){
		date_default_timezone_set('Europe/Warsaw'); // TODO na zendowo
		ini_set('max_execution_time',10480);
		$this->bootstrap('db');
	}
	
	protected function _initConsole(){
		Zend_Registry::set('console',new My_Loger($this->debug_mail));
	}
	
	protected function _initConfig(){
		
		switch ($_SERVER['HTTP_HOST']){
			case 'localhost':
				$filename = 'application';
				break;
			default:
				die('Nie rozpoznano instancji.');
				break;
		}
		
		Utils::config(Utils::a2o(parse_ini_file(APPLICATION_PATH . "/configs/$filename.ini")));
	}
	
	protected function _initCache(){
		Zend_Registry::set('cache',Zend_Cache::factory('Core','File',
			array('lifetime' => 7200,'automatic_serialization' => true),
			array('cache_dir' => APPLICATION_PATH . '/../tmp/'))
		);
		Zend_Db_Table_Abstract::setDefaultMetadataCache('cache');
	}
	
	protected function _initSession(){
		Zend_Session::setOptions(array(
			'name' => 'w6dni'
		));
	}
	
	protected function _initHelpers(){
    	Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers', 'Helper');		
	}
	
	protected function _initFront (){
		Utils::reg('devel_mode',$this->devel_mode);
		Utils::reg('version',$this->version);
		Zend_Controller_Front::getInstance()
			->registerPlugin(new My_FrontPlugin($this->debug_sql,$this->devel_mode));
	}
	
	protected function _initHeaders(){ 
		header("Pragma: no-cache");
		header('Content-Type: text/html; charset=utf-8'); 
		header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
		header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past	
		header('X-UA-Compatible: IE=8');
	}
	
	/*
	public function _initExtdirect() {
		$front = Zend_Controller_Front::getInstance ();
		$request = new Extjs_Controller_Request_RawJson ();
		$front->setRequest ( $request );
		// if this is a Extjs request we switch response and adds a Extjs helper action for the different controllers		
		if ($front->getRequest ()->isXmlHttpRequest ()) {		
			$response = new Extjs_Controller_Response_Extjs ();
			$front->setResponse ( $response );
			$extjshelper = new Extjs_Controller_Action_Helper_Extjs ();
			Zend_Controller_Action_HelperBroker::addHelper ( $extjshelper );
		}		
	}
	*/
	
}